package com.sxhuayuan.parking.controller.salesman;

import com.sxhuayuan.parking.compenent.Pageable;
import com.sxhuayuan.parking.compenent.web.RespMessage;
import com.sxhuayuan.parking.controller.BaseController;
import com.sxhuayuan.parking.entity.Salesman;
import com.sxhuayuan.parking.service.AgentService;
import com.sxhuayuan.parking.service.SalesmanService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 代理
 * 
 * @author helong
 * @create 2019-08-05 13:52
 */
@RestController("salesmanAgentController")
@RequestMapping("/salesman/agent")
public class AgentController extends BaseController {
	@Resource(name = "salesmanServiceImpl")
	SalesmanService salesmanService;

	@Resource(name = "agentServiceImpl")
	AgentService service;

	@Value("${wechat.rate}")
	private float weixinRate;
	@Value("${alipay.rate}")
	private float alipayRate;

	@GetMapping("/list")
	public RespMessage list() {
		Salesman salesman = salesmanService.getCurrent();
		if (salesman == null) {
			return  invalidToken();
		}
		return successResp(service.findBySalesman(salesman));
	}

	/** 查询所有代理 */
	@RequestMapping("/page/list")
	public RespMessage pageList(@RequestBody Pageable pageable) {
		Salesman salesman = salesmanService.getCurrent();
		if (salesman == null) {
			return  invalidToken();
		}
		return successResp(service.findPage(pageable, salesman));
	}
}
